package top.wuliaodebaozi2.yunpan;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.ashokvarma.bottomnavigation.TextBadgeItem;

public class MainActivity extends AppCompatActivity {

    private int imageViewArray[] = {R.drawable.ic_home_icon,R.drawable.ic_netdisk_icon, R.drawable.ic_settings_icon};
    private String[] strings = {"主页", "网盘","设置"};
    FragmentTransaction transaction;
    FragmentManager manager;
    BottomNavigationBar bar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bar = findViewById(R.id.bottombar);
//角标，如同QQ的红点
        final TextBadgeItem mBadgeItem = new TextBadgeItem()
                .setBorderWidth(4)
                .setAnimationDuration(200)
                .setBackgroundColorResource(R.color.red)
                .setHideOnSelect(false)
                .setText("0");


        bar.addItem(new BottomNavigationItem(imageViewArray[0], strings[0]).setActiveColorResource(R.color.black))
                .addItem(new BottomNavigationItem(imageViewArray[1], strings[1]).setActiveColorResource(R.color.purple_700))
                .addItem(new BottomNavigationItem(imageViewArray[2], strings[2]).setActiveColorResource(R.color.purple_700))
                .setFirstSelectedPosition(0)
                .initialise();

        bar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
            @Override
            public void onTabSelected(int position) {
                manager = getSupportFragmentManager();
                transaction = manager.beginTransaction();
                switch (position){

                    case 0:
                        transaction.replace(R.id.framelayout, HomeFragment.newInstance());
                        mBadgeItem.hide();
                        break;
                    case 1:
                        transaction.replace(R.id.framelayout, AgentWebFragment.newInstance());
                        mBadgeItem.show();

                        break;
                    case 2:
                        transaction.replace(R.id.framelayout, SettingsBoardFragment.newInstance());
                        mBadgeItem.show();
                        break;
                }
                transaction.commit();

            }

            @Override
            public void onTabUnselected(int position) {

            }

            @Override
            public void onTabReselected(int position) {

            }
        });
        //设置初始页面
        setDefaultFragment();


    }

    private void setDefaultFragment() {
        manager = getSupportFragmentManager();
        transaction = manager.beginTransaction();
        transaction.replace(R.id.framelayout, HomeFragment.newInstance());
        transaction.commit();
    }
}